package cn.com.generaldata.os.builder;

import java.io.Serializable;

/**
 * 构建器的抽象类(T: 抽象类的子类, U: 要构建的类)
 */
public abstract class AbstractBuilder<T extends AbstractBuilder<T, U>, U> implements Serializable {
	private static final long serialVersionUID = 10000L;

	private U object;
	protected boolean builded;

	protected AbstractBuilder(U object) {
		this.object = object;
		this.builded = false;
	}

	/**
	 * 构建U.
	 * 
	 * @return
	 */
	public U build() {
		if (!builded) {
			configure();
			builded = true;
		}
		return object;
	}

	/**
	 * 构建的U的对象.
	 * 
	 * @return
	 */
	protected U getObject() {
		return object;
	}

	protected void configure() {
	}
}
